#include <iostream>
#include <cassert>
#include <string>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "comm.hpp"


int main()
{
    int wfd = open(FIFO_NAME.c_str(), O_WRONLY);
    if (wfd < 0)
    {
        perror("open");
    }

    std::string input;
    while (true)
    {
        std::cout << "input:> ";
        getline(std::cin, input); // getline不会保留回车
                                  
        // char buff[BF_SIZE] = {0};
        // fgets(buff, sizeof(buff), stdin); // fgets会保留回车
        // buff[strlen(buff) - 1] = 0;
        
        if (input == "quit")
            break;

        ssize_t s = write(wfd, input.c_str(), input.size());
        assert(s >= 0);
    }

    close(wfd);
    return 0;
}
